﻿using EntityModel.PageListInfor;
using EntityModel.Product;
using IServices.IProductLend;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace AikeApplets.Areas.ProductLend.Controllers
{
    [Area("ProductLend")]
    public class ProductLendController : Controller
    {
        private readonly IProductLend _product;

        public ProductLendController(IProductLend product)
        {
            _product = product;
        }

        public IActionResult Index()
        {
            return View();
        }

        public async Task<IActionResult> GetPageListData(int page, int limit, AikeApplet_ProductLend aikeApplet_Product)
        {
            aikeApplet_Product.PageIndex = page;
            aikeApplet_Product.PageSize = limit;
            DbQueryResult result = await _product.GetProductLendPageListAsync(aikeApplet_Product);
            if (result.Data.Rows.Count == 0) return null;
            var data = result.Data.AsEnumerable().Select(s => new AikeApplet_ProductLend {
                PPID = s.Field<string>("PPID"),
                PPName = s.Field<string>("PPName"),
                PPCompany = s.Field<string>("PPCompany"),
                PPMan = s.Field<string>("PPMan"),
                PPTel = s.Field<string>("PPTel"),
                PPAddress = s.Field<string>("PPAddress"),
                PPFax = s.Field<string>("PPFax"),
                PPEmail = s.Field<string>("PPEmail"),
                PPUrl = s.Field<string>("PPUrl"),
                PPBank = s.Field<string>("PPBank"),
                PPGoods = s.Field<string>("PPGoods"),
                CreateTime = s.Field<DateTime>("CreateTime"),
                CreateOn = s.Field<string>("CreateOn")
            });
            Hashtable hashtable = new Hashtable();
            hashtable.Add("code", 0);
            hashtable.Add("count", result.TotalRecords);
            hashtable.Add("data", data);
            return Ok(hashtable);
        }
    }
}
